<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

App::uses ( 'Controller', 'Controller' );

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
 */

Configure::load ( 'config' );

/**
 * 加载全局公用文件
 */
App::import ( 'Lib', 'Common', array (
		'file' => '/Lib/Common.php' 
) );
class AppController extends Controller {
	
	/**
	 *
	 * @var $components
	 */
	public $components = array (
			'Session',
			'Cookie' 
	);
	public $helpers = array (
			'Form',
			'Html',
			'Session',
			'Js' => array (
					'Jquery' 
			) 
	);
	
	// 分页 每页显示条数
	public $perpage = 40;
	
	// 模板文件后缀名
	public $ext = '.html';
	
	/*
	 * 初始化执行
	 */
	public function beforeFilter() {
		// 是否登陆
		if (is_null ( $this->Cookie->read ( 'uid' ) ) || $this->Cookie->read ( 'uid' ) == 0) {
			$this->set ( "isLogin", false );
		} else {
			$this->set ( "isLogin", true );
			
			// 登陆用户信息
			$this->loadModel ( "User" );
			$UserInfo = $this->User->GetUserByID ( $this->Cookie->read ( 'uid' ) );
			
			$this->set ( "UserInfo", $UserInfo );
		}
		
		// 类型
		$this->set ( "nav_type", strtolower ( $this->params ['controller'] ) );
		$this->set ( "shop_type", strtolower ( $this->params ['action'] ) );
		
		// 网站配置参数
		$this->set ( "config", Cache::read ( 'config' ) );
	}
}
